{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = r'E:\\test_data\\lena.jpg'\n",
    "img = cv2.imread(path)\n",
    "img2 = cv2.imread(path)\n",
    "img3 = cv2.imread(path)\n",
    "img4 = cv2.imread(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# R\n",
    "img[:,:,0] = 0\n",
    "img[:,:,1] = 0\n",
    "cv2.imshow(r'img', img)\n",
    "# B\n",
    "img2[:,:,1] = 0\n",
    "img2[:,:,2] = 0\n",
    "cv2.imshow(r'img2', img2)\n",
    "# G\n",
    "img3[:,:,0] = 0\n",
    "img3[:,:,2] = 0\n",
    "cv2.imshow(r'img3', img3)\n",
    "cv2.imwrite(r'E:\\test_data\\lena_R.png',img)\n",
    "cv2.imwrite(r'E:\\test_data\\lena_B.png',img2)\n",
    "cv2.imwrite(r'E:\\test_data\\lena_G.png',img3)\n",
    "cv2.waitKey() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 颜色空间转换\n",
    "img_hsv = cv2.cvtColor(img4, cv2.COLOR_BGR2HSV)\n",
    "\n",
    "# H\n",
    "cv2.imshow(r'img_hsv_H', img_hsv[:,:,0])\n",
    "# S\n",
    "cv2.imshow(r'img_hsv_S', img_hsv[:,:,1])\n",
    "# V\n",
    "cv2.imshow(r'img_hsv_V', img_hsv[:,:,2])\n",
    "cv2.imwrite(r'E:\\test_data\\lena_hsc_V.png',img_hsv[:,:,2])\n",
    "cv2.imwrite(r'E:\\test_data\\lena_hsc_H.png',img_hsv[:,:,0])\n",
    "cv2.imwrite(r'E:\\test_data\\lena_hsc_S.png',img_hsv[:,:,1])\n",
    "cv2.waitKey() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 销毁所有窗口\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
